<?php
$timeStart      = microtime(true);
//load config
include "../includes/config/config.php";
//create object db
include "../includes/class_mysql.php";
include "../includes/gpc_function.php";
//include ("../includes/phpmailer/function.sendmail.php");
include('includes/functions.php');
include('includes/global.php');
include('includes/functions_sitemap.php');
echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
getLastRun();


ImportClass('rate');
updateRateVCB();

updateOil();
updateNatuGas();

UpdateGoldRate();

ImportClass('weather');
UpdateWeather();

sitemap();
LogCronjob();

echo '<br>========>total time: '.(microtime(true)- $timeStart);


function getLastRun()
{
    global $dbsql,$language,$timeStart;
    $get_Only   = gpc_getBoolGet('time');
    $now_time   = time();
    $last_run   = getConfig('LastRunCronjob');
    echo 'Last run: '.@date('d/m/Y H:i:s',$last_run).'<br>';
    
    if($last_run>$now_time - 100)
    {
        echo '<br>========>total time: '.(microtime(true)- $timeStart);
        exit('exit');
    }
    if($get_Only)
    {
        exit;
    }
    saveConfig('LastRunCronjob',$now_time);    
}

function LogCronjob($msg='')
{
    global $ip;
    $msg    = date('Y-m-d H:i:s').'=> IP:'.$ip."\n\n".$msg;
    $file   = '../docs/log_cronjob.txt';
    $f      = @fopen($file,'a');
    @fwrite($f,$msg."\n\n");
    @fclose($f);    
}
?>